package com.sixth.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sixth.core.annotation.OperaLog;
import com.sixth.core.entity.Notice;
import com.sixth.core.vo.R;
import com.sixth.system.service.impl.NoticeServiceimpl;
import com.sixth.system.vo.NoticeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公告控制器
 *
 * @author Stu YH
 * @date Created in 2024/8/18 18:29
 * @description 提供公告相关的API接口
 * @modified By：
 * @version:
 */
@Api(tags = "公告管理")
@RestController
@RequestMapping("/system/notice")
public class NoticeController {
    @Autowired
    private NoticeServiceimpl noticeService;

    /**
     * 分页查询公告
     * @param noticeVo 查询条件
     * @return 分页查询结果
     */
    @ApiOperation(value = "分页查询公告", notes = "根据查询条件分页查询公告列表")
    @PostMapping("/listByPage")
    public R<Page<Notice>> list(@RequestBody NoticeVo noticeVo) {
        return noticeService.selectByPage(noticeVo);
    }

    /**
     * 获取所有公告
     * @return 所有公告列表
     */
    @ApiOperation(value = "获取所有公告", notes = "获取所有公告信息")
    @GetMapping("/listAllNotice")
    public R<List<Notice>> listAllNotice() {
        return noticeService.listAllNotice();
    }

    /**
     * 添加或修改公告
     * @param notice 公告信息
     * @return 操作结果
     */
    @ApiOperation(value = "添加或修改公告", notes = "添加或修改公告信息")
    @PostMapping("/addUpdate")
    public boolean addUpdate(@RequestBody Notice notice) {
        return noticeService.addUpdate(notice);
    }

    /**
     * 删除单条或多条公告
     * @param noticeIds 公告ID数组
     * @return 删除结果
     */
    @ApiOperation(value = "删除公告", notes = "根据公告ID数组删除公告")
    @OperaLog(value = "删除公告", type = 3)
    @GetMapping("/delete/{noticeIds}")
    public R batchDelete(@PathVariable Long[] noticeIds) {
        return noticeService.delete(noticeIds);
    }

    /**
     * 根据ID获取公告
     * @param noticeId 公告ID
     * @return 公告信息
     */
    @ApiOperation(value = "根据ID获取公告", notes = "根据公告ID获取公告信息")
    @GetMapping("/getByNoticeId/{noticeId}")
    public R<Notice> getById(@PathVariable Long noticeId) {
        return noticeService.getById(noticeId);
    }
}
